#!/usr/bin/perl 
sub GetNBName { 
	open (NBSTAT, "/usr/bin/nmblookup -d 1 -A $_[0] |"); 
	@Output = <NBSTAT>; 
	close NBSTAT;
	@Filtered = grep(/<00>/, @Output);
	$fil = $Filtered[0];
	$fil =~ /(.*?)\</;
	$name = $1;
	$name =~ s/[\s\t]//g;
	return $name;
}

print "\n--- Share\$ Finder ---\n";
print "By AFSoft, (C) 2001\n";
if (!(@ARGV)) {
	print "Utilizzo:\n";
	print "\t$0 <ipaddress>\n";
	print "\tRestituisce il NetBios Name e le condivisioni\n\tnon protette da Password dell'host specificato\n"; 
	exit;
} else {
        $nbname = &GetNBName($ARGV[0]);
}

$ip=$ARGV[0];
if ($nbname ne "") {	
        print "Il NetBIOS Name di $ARGV[0] e\' $nbname\n"; 
	open (SHARES , "|/usr/bin/smbclient -L\\\\$nbname -I $ip -N");
	$condivisioni = <SHARES>;
        close (SHARES); 
        print "\n$condivisioni\n";
	#Aggiunta per X
} else {
	print "\nNessuna condivisione...\n\n";
}


